//
//  BVNewFeatureViewController.m
//  BuyVegetable
//
//  Created by yushanchang on 16/11/7.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVNewFeatureViewController.h"
#import "BVNewFeatureCell.h"

#define NEWFEATURE_CELL_IDENTIFIER @"BVNewFeatureCell"

@interface BVNewFeatureViewController ()
<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
@property (nonatomic, strong) NSArray *imageArr;

@end

@implementation BVNewFeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)setCollectionView:(UICollectionView *)collectionView {
    _collectionView = collectionView;
    [collectionView registerClass:[BVNewFeatureCell class] forCellWithReuseIdentifier:NEWFEATURE_CELL_IDENTIFIER];
}

#pragma mark -
#pragma mark - delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(ScreenW, ScreenH);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    BVNewFeatureCell *newfeature_cell = [collectionView dequeueReusableCellWithReuseIdentifier:NEWFEATURE_CELL_IDENTIFIER forIndexPath:indexPath];
    newfeature_cell.backgroundColor = [UIColor cyanColor];
    newfeature_cell.images = IMAGE_NAMED(self.imageArr[indexPath.row]);
    [newfeature_cell setIndexPath:indexPath index:4];
    return newfeature_cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page = scrollView.contentOffset.x / scrollView.bounds.size.width + 0.5;
    self.pageControl.currentPage = page;
}

- (NSArray *)imageArr {
    if (!_imageArr) {
        _imageArr = @[@"引导页1",@"引导页2",@"引导页3",@"引导页4"];
    }
    return _imageArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
